<?
	$page["title"] = "Users";
	$page["file"] = "users.html";

	include "include/config.inc";
	show_header($page["title"],0);
?>

<?
	show_table_header("CONFIGURATION OF USERS");
	echo "<br>";
?>

<?
	if(isset($register))
	{
		if($register=="add")
		{
			if($password1==$password2)
			{
				$result=add_user($groupid,$name,$surname,$alias,$password1);
			}
		}
		if($register=="delete")
		{
			delete_user($userid);
		}
		if($register=="update")
		{
			if($password1==$password2)
			{
				update_user($userid,$groupid,$name,$surname,$alias,$password1);
			}
		}
	}
?>

<?
	show_table_header("USERS");
	echo "<TABLE BORDER=0 COLS=4 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>";
	echo "<TR><TD WIDTH=\"10%\"><B>Group</B></TD>";
	echo "<TD WIDTH=\"10%\"><B>Alias</B></TD>";
	echo "<TD WIDTH=\"10%\" NOSAVE><B>Name</B></TD>";
	echo "<TD WIDTH=\"10%\" NOSAVE><B>Surname</B></TD>";
	echo "<TD WIDTH=\"10%\" NOSAVE><B>Actions</B></TD>";
	echo "</TR>";

	$result=DBselect("select u.userid,u.alias,u.name,u.surname,g.name from users u,groups g where u.groupid=g.groupid order by g.name,u.alias");
	echo "<CENTER>";
	$col=0;
	for($i=0;$i<DBnum_rows($result);$i++)
	{
		if($col==1)
		{
			echo "<TR BGCOLOR=#EEEEEE>";
			$col=0;
		} else
		{
			echo "<TR BGCOLOR=#DDDDDD>";
			$col=1;
		}
	
		$alias=DBget_field($result,$i,1);
		$name=DBget_field($result,$i,2);
		$surname=DBget_field($result,$i,3);
		$group=DBget_field($result,$i,4);
		$userid_=DBget_field($result,$i,0);
		echo "<TD>$group</TD>";
		echo "<TD>$alias</TD>";
		echo "<TD>$name</TD>";
		echo "<TD>$surname</TD>";
		echo "<TD><A HREF=\"users.html?register=change&userid=$userid_\">Change</A> - <A HREF=\"media.html?userid=$userid_\">Media</A>";
		echo "</TD>";
		echo "</TR>";
	}
	echo "</TABLE>";
?>

<?
	echo "<br>";

	insert_user_form($userid);
?>

<?
	show_footer();
?>
